package com.hp.test;

import com.hp.entity.ApplyDB;
import com.hp.mapper.ApplyMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class applytest {
    private SqlSessionFactory sqlSessionFactory = null;
    public static ApplyMapper mapper;
    public static SqlSession sqlSession;

    @Before
    public void init() throws IOException {
        SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
        InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
        sqlSessionFactory = sqlSessionFactoryBuilder.build(is);
        sqlSession = sqlSessionFactory.openSession();
        mapper = sqlSession.getMapper(ApplyMapper.class);
    }

    @Test
    public void cs() {
        List<ApplyDB> app = mapper.app();
        for (ApplyDB applyDB : app) {
            System.out.println(applyDB);
        }
    }

    @Test
    public void cs1(){
        List<ApplyDB> ap = mapper.ap(3);
        for (ApplyDB applyDB : ap) {
            System.out.println(applyDB);
        }
    }

    @Test
    public void cs2(){
        List<ApplyDB> mohu = mapper.mohu("%毛%","接力赛");
        for (ApplyDB applyDB : mohu) {
            System.out.println(applyDB);
        }
    }

    @Test
    public void cs3(){
        ApplyDB ab = new ApplyDB();
        ab.setAge("27");
        ab.setClassName("魏");
        ab.setGame("打东吴");
        ab.setName("曹");
        mapper.Tj(ab);
        sqlSession.commit();
    }

    @Test
    public void cs4(){
        ApplyDB ac = new ApplyDB();
        ac.setApplyId(2);
        ac.setName("关羽");
        mapper.Xg(ac);
        sqlSession.commit();
    }

    @Test
    public void cs5(){
        mapper.Sc(4);
        sqlSession.commit();
    }
}